package cn.gailvlun.gll.presentation.apartment.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import cn.gailvlun.gll.net.apartment.room.RoomType;
import cn.gailvlun.gll.presentation.apartment.ApartmentManageFragment;



public class ApartmentManagePagerAdapter extends FragmentStatePagerAdapter {
    private boolean isPermission;
    public ApartmentManagePagerAdapter(FragmentManager fm, boolean isPermission) {
        super(fm);
        this.isPermission = isPermission;
    }

    @Override
    public Fragment getItem(int position) {
        if (isPermission) {
            switch (position) {
                
                case 0: {
                    return ApartmentManageFragment.newInstance(RoomType.created);
                }
                case 1: {
                    return ApartmentManageFragment.newInstance(RoomType.applied);
                }
                default: {
                    return null;
                }
            }
        } else {
            return ApartmentManageFragment.newInstance(RoomType.applied);
        }
    }

    @Override
    public int getCount() {
        if (isPermission) {
            return 2;
        } else {
            return 1;
        }
    }

    private ApartmentManageFragment mCurrentFragment;

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        super.setPrimaryItem(container, position, object);
        mCurrentFragment = (ApartmentManageFragment) object;
    }

    public ApartmentManageFragment getCurrentFragment() {
        return mCurrentFragment;
    }
}
